(setq backup-directory-alist `(("." . "~/.saves")))
(setq backup-by-copying t)
(setq inhibit-startup-message t)

;; add renpy mode
(load "~/.emacs.d/renpy.el")

;; add paren face mode
(load "~/.emacs.d/paren-face.el")

;; *scratch* is a Scheme file
(setq initial-major-mode 'scheme-mode)

(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")

(require 'package)
(add-to-list 'package-archives
             '("melpa-stable" . "http://stable.melpa.org/packages/"))

(package-initialize)

(setq-default indent-tabs-mode nil)

(defun toggle-fullscreen ()
  "Toggle full screen on X11"
  (interactive)
  (when (eq window-system 'x)
    (set-frame-parameter
     nil 'fullscreen
     (when (not (frame-parameter nil 'fullscreen)) 'fullboth))))

(global-set-key [f11] 'toggle-fullscreen)
(setq explicit-shell-file-name "/bin/sh")
(set-frame-parameter nil 'background-mode 'dark)

(global-linum-mode t)

(add-hook 'scheme-mode-hook #'paren-face-mode)
(add-hook 'inferior-scheme-mode-hook #'paren-face-mode)

;; Connect web-mode to php files
(add-to-list 'auto-mode-alist '("\\.php\\'" . web-mode))

(load "~/.emacs.d/quack.el")

(require 'quack)

(setq quack-default-program "kawa")
(setq quack-run-scheme-always-prompts-p nil)

(add-hook 'scheme-mode-hook 'paredit-mode)
(add-hook 'scheme-mode-hook 'hs-minor-mode)

(global-set-key (kbd "C-h TAB") 'hs-toggle-hiding)

;; Greek letters
(defun pretty-greek ()
  (let ((greek '("alpha" "beta" "gamma" "delta" "epsilon" "zeta" "eta" "theta" "iota" "kappa" "lambda" "mu" "nu" "xi" "omicron" "pi" "rho" "sigma_final" "sigma" "tau" "upsilon" "phi" "chi" "psi" "omega")))
    (setq code 97)
    (while greek
      (setq word (car greek))
      (font-lock-add-keywords nil
                              `((,(concat "\\(^\\|[^a-zA-Z0-9]\\)\\(" word "\\)[a-zA-Z]")
                                 (0 (progn (decompose-region (match-beginning 2) (match-end 2))
                                           nil)))))
      (font-lock-add-keywords nil 
                              `((,(concat "\\(^\\|[^a-zA-Z0-9]\\)\\(" word "\\)[^a-zA-Z]")
                                 (0 (progn (compose-region (match-beginning 2) (match-end 2)
                                                           ,(make-char 'greek-iso8859-7 code))
                                           nil)))))
      (setq code (+ code 1))
      (setq greek (cdr greek)))))

(add-hook 'scheme-mode-hook 'pretty-greek)
(add-hook 'inferior-scheme-mode-hook 'pretty-greek)

;; Scheme keywords
(defun scheme-add-keywords (face-name keyword-rules)
  (let* ((keyword-list (mapcar #'(lambda (x)
                                   (symbol-name (cdr x)))
                               keyword-rules))
         (keyword-regexp (concat "(\\("
                                 (regexp-opt keyword-list)
                                 "\\)[ \n]")))
     (font-lock-add-keywords 'scheme-mode
                             `((,keyword-regexp 1 ',face-name))))
  (mapc #'(lambda (x)
            (put (cdr x)
                 'scheme-indent-function
                 (car x)))
        keyword-rules))

(add-to-list 'auto-mode-alist '(".sld" . scheme-mode))
(add-to-list 'auto-mode-alist '(".sxml" . scheme-mode))

(scheme-add-keywords
 'font-lock-keyword-face
 '((1 . when)
   (1 . unless)
   (2 . let1)
   (2 . define-simple-class)
   (1 . error)
   (1 . repeat)
   (0 . import)
   (1 . object-with-ancestors)
   (0 . object)
   (1 . memoize)))
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(scheme-program-name "kawa-r7"))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
